package cn.lin.controller;

import cn.lin.domain.Classes;
import cn.lin.domain.Organization;
import cn.lin.domain.Role;
import cn.lin.service.ClassesService;
import cn.lin.util.KeyWords;
import cn.lin.vo.ClassesVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/classes")
public class ClassesController {
  @Autowired
  private ClassesService classesService;

    //学生何老师加入的班级，进行中
    @RequestMapping("/findclassesstar")
    public List<ClassesVo> findclassesstar(@RequestParam("id") int id) {
    Role role= classesService.findUser(id);
    if("学生".equals(role.getRoleName())){
        return  classesService.findeteacherclassesallstar(id, KeyWords.is_star);
    }else if("老师".equals(role.getRoleName())){
        return  classesService.teacherstar(id, KeyWords.is_star);
    }
    return null;
  }

    @RequestMapping("role")
    public Role findRoleById(@RequestParam("id") int id) {
        return classesService.findUser(id);
    }

//老师和学生加入的班级，已经完成
  @RequestMapping("/findclassesend")
  public List<ClassesVo> findclassesend(@RequestParam("id") int id) {
    Role role= classesService.findUser(id);
    if("学生".equals(role.getRoleName())){
      return  classesService.findeteacherclassesallend(id, KeyWords.is_end);
    }else if("老师".equals(role.getRoleName())){
      return  classesService.teacherend(id, KeyWords.is_end);
    }
    return null;
  }


  //渲染机构
  @RequestMapping("/findOrganization")
  public List<Organization> findOrganization() {
      return classesService.findAllOrganization();
  }
}
